package com.leantech.android.browser.utils

import android.app.Dialog
import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.view.Gravity
import android.view.LayoutInflater
import com.leantech.android.browser.R
import com.leantech.android.browser.databinding.LayoutPermissionExplainBinding
import com.qmuiteam.qmui.skin.QMUISkinManager
import com.qmuiteam.qmui.util.QMUIDisplayHelper
import com.qmuiteam.qmui.widget.dialog.QMUIBaseDialog
import splitties.resources.color

object PermissionExplainDialog {

    fun createDialog(context: Context, title: String, desc: String): Dialog {
        return QMUIBaseDialog(context, com.qmuiteam.qmui.R.style.QMUI_Dialog).apply {
            val contentBinding = LayoutPermissionExplainBinding.inflate(LayoutInflater.from(context))
            contentBinding.title.text = title
            contentBinding.content.text = desc
            window?.setBackgroundDrawable(ColorDrawable(context.color(android.R.color.transparent)))
            window?.setDimAmount(0f)
            setSkinManager(QMUISkinManager.defaultInstance(context))
            setContentView(contentBinding.root)
            setCanceledOnTouchOutside(true)
            setCanceledOnTouchOutside(true)

            window?.attributes?.apply {
                gravity = Gravity.TOP
                width = QMUIDisplayHelper.getScreenWidth(context)
                windowAnimations = R.style.PermissionExplainDialog
                window?.attributes = this
            }
        }
    }

}